package com.tanhua.server.service;

import com.tanhua.autoconfig.template.HuanXinTemplate;
import com.tanhua.dubbo.api.UserApi;
import com.tanhua.model.domain.User;
import com.tanhua.model.vo.HuanXinUserVo;
import com.tanhua.server.interceptor.UserHolderThreadLocal;
import org.apache.dubbo.config.annotation.DubboReference;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Description: test
 * @Create by: JJ菜菜
 * @Date: 2021/12/4 23:11
 */
@Service
public class HuanXinService {

    @Autowired
    private HuanXinTemplate huanXinTemplate;

    @DubboReference
    private UserApi userApi;

    /**
     * 查询当前用户的环信账号
     * 获取用户id，查询用户账号
     * @return
     */
    public HuanXinUserVo findHuanXinUser() {

        Long userId = UserHolderThreadLocal.getId();
        // 调用userApi
        User user = userApi.findById(userId);
        if(user == null){
            return null;
        }
        // 获取返回环信的账号，密码
        String hxUser = user.getHxUser();
        return new HuanXinUserVo(hxUser, user.getHxPassword());
    }
}
